﻿using System;
using System.Windows.Forms;

namespace CreateReport
{
    public partial class Frm_Main : Form
    {
        public Frm_Main()
        {
            InitializeComponent();
        }

        private void Frm_Main_Load(object sender, EventArgs e)
        {
            string version = " v20210323";
            this.Text += version;
            cb_year.SelectedIndex = 0;
            cb_province.SelectedIndex = 0;
            lbl_FileName.Text = "";
        }

        private void btn_SelectFile_Click(object sender, EventArgs e)
        {
            openFileDialog.FileName = "";
            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            openFileDialog.Filter = "Word文档|*.docx|Word文档（97-2003）|*.doc";
            openFileDialog.Title = "请选择模板文件";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                lbl_FileName.Text = this.openFileDialog.FileName;
            }
        }

        private void btn_CreateReport_Click(object sender, EventArgs e)
        {
            Operations operations = new Operations();
            string FileCategory = operations.Classification(lbl_FileName.Text);
            string Year = cb_year.SelectedItem.ToString();
            string Province = cb_province.SelectedItem.ToString();
            string SrcFileName = lbl_FileName.Text;
            if (FileCategory=="Error")
            {
                MessageBox.Show("模板文件选择错误！请重新选择！", "错误！", MessageBoxButtons.OK, MessageBoxIcon.Error);
                lbl_FileName.Text = "";
                return;
            }
            else
            {
                if (operations.CreateReport(Year, Province, FileCategory, SrcFileName)!=0)
                {
                    MessageBox.Show("批量生成巡检报告成功！", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.lbl_FileName.Text = "";
                }
                else
                {
                    MessageBox.Show("批量生成巡检报告失败！", "失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }            
        }
    }
}
